//
//  HNSH_CashierPayCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/2.
//

#import "HNSH_CashierPayCell.h"

@interface HNSH_CashierPayCell ()

@property (nonatomic, strong)UIView * bgView;
@property (nonatomic, strong)UIImageView * imgView;
@property (nonatomic, strong)UILabel * titleLabel;
@property (nonatomic, strong)UILabel * desLabel;
@property (nonatomic, strong)UIButton * selBtn;

@end

@implementation HNSH_CashierPayCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor appBGColor];
        [self configView];
    }
    return self;
}

- (void)configView {
    [self addAllViews];
    [self addAllLayout];
}


//MARK: Myself Methods
- (void)addAllViews{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.imgView];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.desLabel];
    [self.bgView addSubview:self.selBtn];
}

- (void)addAllLayout{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(65);
        make.top.mas_equalTo(12);
    }];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.width.height.mas_equalTo(38);
        make.centerY.mas_equalTo(self.bgView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(10);
        make.right.mas_equalTo(-60);
        make.height.mas_equalTo(25);
        make.top.mas_equalTo(10);
    }];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(2);
        make.height.mas_equalTo(17);
    }];
    [self.selBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.width.height.mas_equalTo(20);
        make.centerY.mas_equalTo(self.bgView);
    }];
}

//MARK: Setter Methods
- (void)setModel:(HNSH_CashierPayMethodItem *)model{
    _model = model;
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:[UIImage imageNamed:@"icon_place"]];
    self.titleLabel.text = model.title;
    self.desLabel.text = model.desc;
}

- (void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
    
    self.selBtn.selected = isSelected;
}

//MARK: Getter Methods
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 10;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
    }
    return _imgView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont boldSystemFontOfSize:18];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
    }
    return _titleLabel;
}

- (UILabel *)desLabel{
    if (!_desLabel) {
        _desLabel = [UILabel new];
        _desLabel.font = [UIFont systemFontOfSize:12];
        _desLabel.textColor = [UIColor appGrayLabelColor];
    }
    return _desLabel;
}

- (UIButton *)selBtn{
    if (!_selBtn) {
        _selBtn = [UIButton new];
        _selBtn.userInteractionEnabled = NO;
        [_selBtn setImage:[UIImage imageNamed:@"base_select_off"] forState:UIControlStateNormal];
        [_selBtn setImage:[UIImage imageNamed:@"base_select_on"] forState:UIControlStateSelected];
    }
    return _selBtn;
}
@end
